package com.gamebox.view;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;

import com.gamebox.dao.GameDao;
import com.gamebox.javaBean.Game;
import com.gamebox.javaBean.User;

public class UserDetailDialog extends JDialog{

	/**
	 * 
	 */
	private static final long serialVersionUID = 2845706587252420927L;
	private User user;
	public UserDetailDialog(final User user){
		this.user = user;
		this.setTitle("用户详情");
		this.setBounds(100, 100, 600, 400);
		Container con=this.getContentPane();  
		con.setLayout(null);
		JLabel nameLabel=new JLabel("用户名:");
		JLabel name = new JLabel(user.getName());
		nameLabel.setBounds(100,10, 80, 30);
		name.setBounds(200, 10, 100, 30);
		JLabel markLabel=new JLabel("昵称:");
		JLabel mark=new JLabel(user.getNickName());
		markLabel.setBounds(100, 50, 100, 30);
		mark.setBounds(200, 50, 100, 30);
		JLabel myMark=new JLabel("设置分组:");
		final GameDao gameDao = new GameDao();
		List<String> groups = gameDao.getGroups();
		final JComboBox markText = new JComboBox(groups.toArray());
		myMark.setBounds(100, 90, 100, 30);
		markText.setBounds(200, 90, 100, 30);
		JButton confirmMarkBt = new JButton("确认");
		confirmMarkBt.setBounds(350, 90, 100, 30);
		confirmMarkBt.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				String groupName = (String) markText.getSelectedItem();
				int groupId = gameDao.getGroupByName(groupName);
				gameDao.updateGroup(user.getId(),groupId);
				JOptionPane.showMessageDialog(null, "设置分组成功");
			}
		});
		JLabel remarkLabel = new JLabel("游戏列表");
		remarkLabel.setBounds(100, 140, 100, 30);
		List<Game> temp = gameDao.getAllGames(user);
		String s[] = new String[temp.size()];
		for(int i=0;i<temp.size();i++){
			s[i] = temp.get(i).getName();
		}
		JList remarkList = new JList(s);
		remarkList.setBounds(200, 140, 200, 150);
		con.add(nameLabel);
		con.add(name);
		con.add(markLabel);
		con.add(mark);
		con.add(myMark);
		con.add(markText);
		con.add(confirmMarkBt);
		con.add(remarkLabel);
		con.add(remarkList);
		this.setVisible(true);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
	}
}
